<?php
	$no=$_POST['no'];
	$name=$_POST['name'];
	if ($no||$name) {
		
	}else{
		echo '<p>请输入查询项
				</p>';
		exit;
	}
	
	$db=new mysqli('localhost','root','112233456','test');
	if(mysqli_connect_errno()){
		echo '<p>Error:Could not connect to database<br />
						Please go back and try again.
				</p>';
		exit;
	}
	$db->query('set names utf8');
	
	if ($no) {
		$query="select no,name,sex,id,dormitory_no,address from student where no=?";	
		$stmt=$db->prepare($query);
		$stmt->bind_param('s',$no);	
	}else if ($name) {
		$query="select no,name,sex,id,dormitory_no,address from student where name=?";
		$stmt=$db->prepare($query);
		$stmt->bind_param('s',$name);			
	}
	
	$stmt->execute();	
	
	$result = $stmt->get_result();
	if($result->num_rows==0){
		echo '<p>无数据
				</p>';
		exit;
	}	

	$titArray=array("学号","姓名","性别","身份证号","宿舍号","详细家庭住址");	
	echo '
		<fieldset>
			<legend>查询结果 </legend>
	';
	$row = $result->fetch_array(MYSQLI_NUM);
	foreach($titArray as $key=>$val){
		echo '
			<p>
				<label>'.$val.'</label>		
				<label>'.$row[$key].'</label>
			</p>	
		';		
	}
	echo '</fieldset>';